package com.leyou.auth.web;

import com.leyou.auth.service.ClientService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("client")
public class ClientController {

    private final ClientService clientService;

    public ClientController(ClientService clientService) {
        this.clientService = clientService;
    }

    /**
     * 根据服务的clientId以及secret进行服务校验，校验成功返回配置文件中的私密key
     * 私密key很重要，===》secretKey===>JwtParser(解析token)
     * @param clientId
     * @param secret
     * @return
     */
    @GetMapping("key")
    public ResponseEntity<String> getSecretKey(
            @RequestParam("clientId") String clientId,
            @RequestParam("secret") String secret){
        return ResponseEntity.ok(this.clientService.getSecretKey(clientId, secret));
    }
}
